package com.changou.system.FIlter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.InetSocketAddress;

//把这个类交给spring管理
@Component
//实现这两个接口
public class IpFilter implements Ordered,GlobalFilter {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("这是第一个过滤器ipFile");
        ServerHttpRequest request = exchange.getRequest();
        InetSocketAddress remoteAddress = request.getRemoteAddress();
        //打印出请求的ip
        System.out.println("ip"+remoteAddress.getHostName());
        //放行
        return chain.filter(exchange);

    }

    @Override
    public int getOrder() {
        return 1;
    }
}
